//
//  NFSRecommendViewController.m
//  NeedForSpeed
//
//  Created by dlios on 15/10/15.
//  Copyright (c) 2015年 Avenger. All rights reserved.
//

#import "NFSRecommendViewController.h"
#import "BaseHeader.h"
@interface NFSRecommendViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,retain)NSMutableArray *dataArr;
@property(nonatomic,retain)UITableView *myTable;
@end

@implementation NFSRecommendViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    _dataArr = [[NSMutableArray alloc]init];
    
    
    _myTable = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64)];
    [_myTable setDelegate:self];
    [_myTable setDataSource:self];
    [self.view addSubview:_myTable];
    
    [self getData];
    
}


-(void) getData
{
    [AFNETWORK getdataWithString:[NSString stringWithFormat:@"http://app.api.autohome.com.cn/autov5.0.0/news/newslist-pm1-c0-nt0-p1-s30-l0.json"] block:^(id block) {
        
        self.dataArr = [[NFSRecommendModel dealWithDataByDictionary:block] mutableCopy];
        
        [_myTable reloadData];
    }];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArr.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 80;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellId = @"commonCell";
    
    NFSCommonTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    NFSRecommendModel *model = [_dataArr objectAtIndex:indexPath.row];
    if (!cell) {
        cell = [[NFSCommonTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
        
    }
    [cell getDataByModel:model];
    return cell;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
